import requests
import UAS
import multiprocessing
# 目标网站：https://sc.chinaz.com/tupian/qinglvtupian.html
headers_ = UAS.headers
result = []
urls = ['https://scpic2.chinaz.net/files/default/imgs/2022-12-16/039f4a2c9452823e_s.jpg',
        'https://scpic2.chinaz.net/files/default/imgs/2022-12-14/674684ee3d950489_s.jpg',
        'https://scpic2.chinaz.net/files/default/imgs/2022-12-14/1844882a517acbe9_s.jpg',
        'https://scpic2.chinaz.net/files/default/imgs/2022-11-02/802ee96ae9162177_s.jpg',
        'https://scpic2.chinaz.net/files/default/imgs/2022-10-17/45136153822e2fce_s.jpg',
        'https://scpic2.chinaz.net/files/default/imgs/2022-11-14/1e48e36fb9d4a109_s.jpg'
]

def GetResponse(url,queue):
    # 获取响应
    queue.put(url)
    response = requests.get(url,headers=headers_)
    data = response.content
    with open(url.split('/')[-1].split('.')[0] + '.jpg','wb') as f:
        f.write(data)
    return data


if __name__ == '__main__':
    jobs = []
    queues = []
    for url in urls:
        queue = multiprocessing.Queue()
        queues.append(queue)
        p = multiprocessing.Process(target=GetResponse,args=(url,queue))
        jobs.append(p)
        p.start()
    for i,t in enumerate(jobs):
        t.join()
        result.append(queues[i].get())
    print(result)